package org.onion.pattern.event.io.codec;

import org.onion.pattern.event.io.EventDeserializer;
import org.onion.pattern.event.io.EventSerializer;


public class ProtobufEventCodec implements EventSerializer, EventDeserializer {
    public static final ProtobufEventCodec INSTANCE = new ProtobufEventCodec();

    public static final String TYPE = "protobuf";

    @Override
    public <T> T deserialize(byte[] payload, Class<T> clazz) {
        return ProtostuffUtils.deserialize(payload, clazz);
    }

    @Override
    public String type() {
        return TYPE;
    }

    @Override
    public byte[] serialize(Object payload) {

        return ProtostuffUtils.serialize(payload);

////        if (ProtobufCodec.this.protobufBlacklist.contains(clazz.getName())) {
////            return blacklistEncoder.encode(in);
////        } else {
//            ByteBuf out = ByteBufAllocator.DEFAULT.buffer();
////            if (MessageLite.class.isAssignableFrom(clazz)) {
////                out.writeBytes(((MessageLite)in).toByteArray());
////            } else {
//                ByteBufOutputStream os = new ByteBufOutputStream(out);
//                ProtostuffUtils.serialize(os, in);
////            }
//
//            return out;
////        }
//
    }

    @Override
    public int getOrder() {
        return 0;
    }

}
